﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace My_Dialog
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Open_Click(object sender, EventArgs e)
        {
            //创建打开文件对话框
            OpenFileDialog dialog = new OpenFileDialog();
           // 设置默认的文件扩展名为.cs
            dialog.DefaultExt = ".cs";

            //设置文件类型过滤器，只显示扩展名为.cs的文件
            dialog.Filter = "C #源码文件|*.cs ";

            //GetFullPath,将 相对路径 转换为 绝对路径（完整路径）
            dialog.InitialDirectory = Path.GetFullPath(".");

            //显示文件选择对话框，并检查用户是否点击了"确定"按钮
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string filename = dialog.FileName;
                MessageBox.Show ("选中了" + filename);
            }
        }

        private void Save_Click(object sender, EventArgs e)
        {
            //创建打开文件对话框
            SaveFileDialog dialog = new SaveFileDialog();
            // 设置默认文件名
            dialog.FileName = "新的文本文件";

            // 设置默认扩展名

            dialog.DefaultExt = ".txt";

            // 设置文件过滤器

            dialog.Filter = "Text documents (.txt)|*.txt";

  
            //显示文件选择对话框，并检查用户是否点击了"确定"按钮
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string filename = dialog.FileName;
                MessageBox.Show("选中了" + filename);
            }
        }

        private void chose_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog =   new FolderBrowserDialog();
            //GetFullPath将相对路径转换为绝对路径
            dialog.SelectedPath = Path.GetFullPath(".");

            //显示文件选择对话框，并检查用户是否点击了"确定"按钮
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string filename = dialog.SelectedPath;
                MessageBox.Show("选中了" + filename);
            }
        }



        // 新增的帮助事件处理方法
        private void ColorDialog_HelpRequest(object sender, EventArgs e)
        {
            MessageBox.Show("颜色选择帮助：\n\n" +
                            "1. 从左侧选择预设颜色\n" +
                            "2. 点击确定应用颜色\n" +
                            "3. 自定义颜色功能已禁用",
                            "颜色帮助",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
        }
        private void button_Click(object sender, EventArgs e)
        {
            ColorDialog dialog = new ColorDialog();
            //自定义颜色按钮隐藏
            dialog.AllowFullOpen = false;
            //显示帮助按钮,用户点击该按钮会触发 HelpRequest 事件
            dialog.ShowHelp = true;
            // 添加帮助事件处理
            dialog.HelpRequest += ColorDialog_HelpRequest;
            //设置对话框初始颜色为当前按钮的前景色
            dialog.Color = button.ForeColor;//Color是自定义的按钮

            //显示文件选择对话框，并检查用户是否点击了"确定"按钮
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                
                button.ForeColor = dialog.Color;
                MessageBox.Show("修改成功");
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {

            //控制字体对话框中是否显示颜色选择选项
            FontDialog dialog = new FontDialog();
            dialog.ShowColor = true;
            dialog.Font = button5.Font;
            dialog.Color = button.ForeColor;

            //if(dialog.ShowDialog()!= DialogResult.Cancel)
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                //将按钮设置为对话框中的属性
                button5.Font = dialog.Font;
                button5.ForeColor = dialog.Color;
            }
        }
    }
}
